<?php

	/**
	 * @see Bike_Js_VarPart_Setting
	 */
	require_once 'Bike/Js/VarPart/Setting.php';
	
	
	class Bike_Js_VarPart_Method extends Bike_Js_VarPart_Setting
	{
		static protected $_argsNeeded = True;
		
		protected $_argsStr;
		
		public function getArgsNeeded()
		{
			$className = get_class($this);
			$res = '';
			eval('$res='.$className.'::$_argsNeeded;');
			return $res;
		}
		
		protected function getArgsStrPart()
		{
			if(is_null($this->_argsStr))
			{
				$this->_argsStr = $this->getArgsNeeded() ? '('.join(',', $this->getArgs()).')' : '';
			}
			return $this->_argsStr;
		}
		
		public function _toString()
		{
			$str = ($this->getOffsetStrPart()) ? substr(parent::_toString(), 0, -strlen($this->getOffsetStrPart())) : parent::_toString();
			return $str.$this->getArgsStrPart().$this->getOffsetStrPart();
		}

		protected function getArgs()
		{			$args = array();
			$settings = $this->getSettings();
			if($this->getPart() == 'for')
			{
				$newSettings = array();
				if(sizeof($settings) == 1 && is_array(reset($settings)))
				{
					$key = key($settings);
					array_push($newSettings, $this->js()->ForCodeContainer($settings[$key]));
				}
				else
				{
					array_push($newSettings, $this->js()->ForCodeContainer(array_values($settings)));
				}
				$settings = $newSettings;
			}
			foreach($settings as $key => $value)
			{
				$args[$key] = $this->_prepareValue($value);
			}
			return $args;
		}

		protected function _setArgs(array $Args)
		{
			$this->unsetSettings();
			$this->setSettings($Args);
			return $this;
		}

		public function _args()
		{			$args = func_get_args();
			return $this->_setArgs($args);
		}
		
		public function getVarCaching()
		{
			return False;
		}
	}
